package org.west.sky.frame.activiti.study.chapter16;

import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.west.sky.frame.activiti.study.util.ActivitiEngineUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * author: chz
 * date: 2025/6/6
 * description: 条件顺序流
 */
public class RunDemo16_1_2 extends ActivitiEngineUtil {

    public static void main(String[] args) {
        RunDemo16_1_2 runDemo16_1_2 = new RunDemo16_1_2();
        runDemo16_1_2.run();
    }

    public void run() {
        loadActivitiConfigAndInitEngine();
        ProcessDefinition processDefinition = deployByClassPathResource("processes/chapter16/Chapter16_1_2.bpmn20.xml");

        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());

        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        System.out.println("====当前流程：" + processInstance.getId() + "进行到：" + task.getName() + "：任务节点");

        Map<String, Object> variables = new HashMap<>();
        variables.put("totalPrice", 19999);
        taskService.complete(task.getId(),variables);

        Task task2 = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        System.out.println("====当前流程：" + processInstance.getId() + "进行到：" + task2.getName() + "：任务节点");

        taskService.complete(task2.getId());

        closeEngine();
    }
}
